﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Model;
using BLL;
namespace UI
{
    public partial class 账单查询 : Form
    {
        public 账单查询()
        {
            InitializeComponent();
        }

        public void FuKuanRen() {
            //执行操作
            SqlDataReader dr = 账单查询BLL.query();
            //打开阅读器
            while (dr.Read())
            {
                ListViewItem li = new ListViewItem(dr[1].ToString());
                li.SubItems.Add(dr[2].ToString());
                li.SubItems.Add(dr[3].ToString());
                li.SubItems.Add(dr[4].ToString());
                li.SubItems.Add(dr[5].ToString());
                li.SubItems.Add(dr[6].ToString());
                li.SubItems.Add(dr[7].ToString());
                this.listView1.Items.Add(li);
            }
            //关闭
            dr.Close();
        }
        public void XiaoFei() {
            this.listView1.Items.Clear();
            this.listView2.Items.Clear();
            //执行操作
            SqlDataReader dr = 账单查询BLL.XiaoFei();
            //打开阅读器
            while (dr.Read())
            {
                ListViewItem li = new ListViewItem(dr[1].ToString());
                li.SubItems.Add(dr[2].ToString());
                li.SubItems.Add(dr[3].ToString());
                li.SubItems.Add(dr[4].ToString());
                li.SubItems.Add(dr[5].ToString());
                li.SubItems.Add(dr[6].ToString());
                li.SubItems.Add(dr[7].ToString());
                this.listView1.Items.Add(li);
            }
            //关闭
            dr.Close();
        
        
        }
        private void 账单查询_Load(object sender, EventArgs e)
        {
            //执行操作
            DataSet ds = 账单查询BLL.FuKuanRen();
            this.comboBox1.DataSource = ds.Tables[0];
            this.comboBox1.DisplayMember = "UserName";
            this.comboBox1.ValueMember = "UserID"; 
            FuKuanRen();
            XiaoFei();
        }
        //全局变量
        Model_ConsumerBill_Tables_ConsumerDetail_Vips m = new Model_ConsumerBill_Tables_ConsumerDetail_Vips();
        //时间查询
        public void ShijianChaXun(Model_ConsumerBill_Tables_ConsumerDetail_Vips m,string a)
        {
            this.listView1.Items.Clear();
            SqlDataReader dr = 账单查询BLL.ShijianChaXun(m,a);
            //打开阅读器
            while (dr.Read())
            {
                ListViewItem li = new ListViewItem(dr[1].ToString());
                li.SubItems.Add(dr[2].ToString());
                li.SubItems.Add(dr[3].ToString());
                li.SubItems.Add(dr[4].ToString());
                li.SubItems.Add(dr[5].ToString());
                li.SubItems.Add(dr[6].ToString());
                li.SubItems.Add(dr[7].ToString());
                this.listView1.Items.Add(li);
            }
            //关闭
            dr.Close();

        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = this.dateTimePicker1.Value.ToString();
            m.CBEndDate = this.dateTimePicker2.Value.ToString();
            //调用方法
            ShijianChaXun(m,"");
        }

        private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = this.dateTimePicker1.Value.ToString();
            m.CBEndDate = this.dateTimePicker2.Value.ToString();
            //调用方法
            ShijianChaXun(m,"");
        }

        private void 今天ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " 00:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + (DateTime.Now.Day+1) + " 00:00:00.000";
            //调用方法
            ShijianChaXun(m,null);
        }

        private void 昨天ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string mm = DateTime.Now.Month > 9 ? DateTime.Now.Month.ToString() : "0" + DateTime.Now.Month;
            string dd = DateTime.Now.Day > 9 ? DateTime.Now.Day.ToString() : "0" + DateTime.Now.Day;
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + mm + "-" + (int.Parse(dd) - 1) + " 00:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + mm + "-" + dd + " 00:00:00.000";
            //调用方法
            ShijianChaXun(m,null);
        }

        private void 前天ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + (DateTime.Now.Day - 2) + " 00:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + (DateTime.Now.Day - 1) + " 00:00:00.000";
            //调用方法
            ShijianChaXun(m, null);
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now; //当前时间
            //当前时间
            m.CBEndDate = dt.Year + "-" + dt.Month + "-" + (dt.Day + 1) + " 00:00:00.000";
            //获取当前星期几
            string weekName = dt.DayOfWeek.ToString();
            switch (weekName)
            {
                case "Sunday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 6) + " 00:00:00.000";
                    break;
                case "Monday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + dt.Day + " 00:00:00.000";
                    break;
                case "Tuesday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 1) + " 00:00:00.000";
                    break;
                case "Wednesday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 2) + " 00:00:00.000";
                    break;
                case "Thursday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 3) + " 00:00:00.000";
                    break;
                case "Friday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 4) + " 00:00:00.000";
                    break;
                case "Saturday":
                    m.CBStartDate = dt.Year + "-" + dt.Month + "-" + (dt.Day - 5) + " 00:00:00.000";
                    break;
            }
            //调用方法
            ShijianChaXun(m, null);
        }

        private void 本月ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-01 01:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + (DateTime.Now.Month + 1) + "-01 01:00:00.000";
            //调用方法
            ShijianChaXun(m, null);
        }

        private void 上月ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //赋值
            m.CBStartDate = DateTime.Now.Year + "-" + (DateTime.Now.Month - 1) + "-01 01:00:00.000";
            m.CBEndDate = DateTime.Now.Year + "-" + DateTime.Now.Month + "-01 01:00:00.000";
            //调用方法
            ShijianChaXun(m, null);
        }

        private void 所有时间ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XiaoFei();
        }

        private void listView1_Click(object sender, EventArgs e)
        {
            this.listView2.Items.Clear();
            //账单编号
            m.CBID = this.listView1.SelectedItems[0].SubItems[0].Text;
            SqlDataReader dr = 账单查询BLL.query(m);
            while (dr.Read())
            {
                ListViewItem li = new ListViewItem(dr[0].ToString());
                for (int i = 1; i < 7; i++)
                {
                    li.SubItems.Add(dr[i].ToString());
                }
                this.listView2.Items.Add(li);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.listView1.Items.Clear();
            m.TableID = textBox1.Text;
            Admins.UserID = int.Parse(this.comboBox1.SelectedValue.ToString());
            SqlDataReader dr = 账单查询BLL.Tiaojianquery(m);
            //打开阅读器
            while (dr.Read())
            {
                ListViewItem li = new ListViewItem(dr[1].ToString());
                li.SubItems.Add(dr[2].ToString());
                li.SubItems.Add(dr[3].ToString());
                li.SubItems.Add(dr[4].ToString());
                li.SubItems.Add(dr[5].ToString());
                li.SubItems.Add(dr[6].ToString());
                li.SubItems.Add(dr[7].ToString());
                this.listView1.Items.Add(li);
            }
            //关闭
            dr.Close();
        }
    }
}
